need to check whether the value is null!Public VoidOnnewmessage (StringMessage){Messagereceived (This,NewMessagereceivedeventargs (Message ));}} Solution 3: create a local delegated copy
Another simple solution is used by many people. The recommended mode is to create a local delegated copy.
Public ClassLocalcopymessenger: imessenger{Public EventEventhandler // Make a copy when an event is triggeredPublic VoidOnnewmessage (StringMessage){VaR target = messagereceived;If(Target! =Null){Target (
More effective C ++: 35 effective methods to improve programming and designChinese version) China-Pub computer New Book recommendation
Basic InformationOriginal Title: more effective C ++: 35 new ways to improve your programs and designsOriginal Press: Addison-Wesley profes
to be inside the destructor itself.Exception-catching, handling. Failure can not allow the exception to spread, out of destructors. In addition, if the customer requests to react to an exception, it is recommended to provide an interface function,For its capture, call processing.Article 9: Never call the virtual function in the construction and destruction processFailure to comply with this clause will also pose a significant risk. Also, you are a Java or C
the inheritance diagram,type need to convert, you must design a new type class , and so on.Terms : Ning to pass -by-reference-to-const Replace pass-by- va LueWhen it comes to this clause, it is stated that the pass-through parameter is in the form of a copy by default in C + +. Which will create a temporary one.The copy. In most cases, it is more efficient to pass a constant reference directly, because it avoids the overhead of two of copies. But t
jumps to its implementation code.2. Key points-The message consists of a receiver, a method name, and a parameter. Send a message to an object is also equivalent to the object "Invoke method ".-All messages sent to an object are handled by the dynamic message dispatch system, which detects the corresponding partyand execute its code.12th: Understand the message forwarding mechanism (what happens when an object receives a message that cannot be read)1. Message forwarding is initiated when the ob
, argv);}View Code3). Dynamic Memory allocationc Dynamic memory allocation and deallocation use malloc (and its variants) and the free function, which only involves allocating and releasing memory, while C + + uses the new and delete keywords and automatically calls the object's constructor. malloc (and its variants)/free with, new/ Delete is used in conjunction with, not confusing.(Note: Individuals think that as long as you thoroughly understand the
Turn from: http://blog.csdn.net/swj524152416/article/details/75418162 we know that in the C + + field, as an advanced reading material, the must-see book is "Effective C + +". and "Effective C #" In C #, is similar to the "
Item m34: how to mix C ++ and C in the same program
For many years, you have been worried about using C ++ in part during programming, just as using multiple compilers to generate programs in the age of all C programming. There is no way to program Multiple compilers, unless different compilers have the same implementa
Effective C # principle 1: Use attributes (property) as much as possible, rather than data members (field)
Effective C # principle 2: Choose ReadOnly instead of const for your constants
Effective C # Principle 3: Select is or as
SETJMP and longjmp non-localized jump statements: Nonlocal refers to, this is not similar to the normal C language goto statement, the statement in a function to jump, but on the stack to jump, may skip many call frames, and then return to the current function call path in a function.
Use setjmp and longjmp where you need attention:1) setjmp and longjmp are used in combination, have their corresponding call order, setjmp before, longjmp in order to be
"Effective C # Quick Notes"-dynamic Programming in C #static types and dynamic types have strengths, and static types allow the compiler to help you find more errors, because the compiler can do most of the checking at compile time. C # is a static type of language, but it adds dynamic types of language features that c
the use of dynamic types in the public API
Prefer to use static types in C # and minimize the scope of dynamic types. If you want to use dynamic features all the time, you should choose a dynamic language rather than C #.
To use dynamic attributes in your program, try not to use them in a public interface, which restricts the dynamic type to a single object (or type).
This seriesEffective
passing constant pointers is a better choice. But if you hit the STL again, and the iterators and function objects are all based on the C language pointers, then back to the original rule: the value of the pass is better than the reference.
Unless noted, this blog article is original, reproduced please link to the form of this article address: http://harttle.com/2015/07/19/effective-cpp-1.html Copyri
Effective C + + Chapter 1. Make yourself accustomed to C + + (Accustoming yourself to C + +) Item 1. View C + + as a language federation (View C + + as a federation of Languages) Consider C
Excerpt from the Houtie version of effective C + + (third edition)Clause IC + + as a multi-paradigm fusion language, can be seen as a language of the Commonwealth, it contains the four major sub-languages:
C. C + + is based on, many times C + + for the problem of th
Recently reading effective C + +, want to make some notes, the same as each module in the book, but it may be inconsistent with the specific order in the module. Will not be involved in every detail of the book, mainly write down what you feel important.What is C + +?C + + is a multi-paradigm programming language (MULT
). Where the container holds objects, iterators are used to traverse the container elements, The generic algorithm is based on an iterator implementation that does not depend on a specific type of function template.2). STL is extensible, as long as you follow the STL standards, you can combine your own containers, iterators, algorithms, etc. with STL. (To make a custom iterator suitable for STL generic algorithms, you need to understand C + + 's trait
Effective C # Quick notes-key additions to C # efficient programmingDirectory
45. Minimize packing and unpacking
46. Create a specialized exception class for your application
47, the use of strong exception security guarantee
48. Try to use secure code
49. Implementing CLS-compliant assemblies
50, the realization of small size, high c
"Effective C + +" read Note 01
size_t is an unsigned (unsigned) type used when calculating the number of C + +. It is also a parameter type accepted by the operator[] function in Vector,deque and string.
Define the declarative and the definition, for the object, the definition is the place where the compiler is allocating memory for this object, and
This article records some of my own understanding and experience when I read effective modern C + +.Item1: Template type derivation1) The reference property cannot pass in a template function by passing a value parameter . This means that if a template function requires a parameter of type reference, it must be declared as reference in the template declaration, otherwise the result of the type deduction wil
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.